home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0013_Automatic sizing of WIN95 Taskbar.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  3.4 KB  |  74 lines

  1.  
  2. {Automatic sizing with taskbar in Win95 and NT-Shell update  }
  3. {Modified by Tim Baker timbaker@mail.infinet.com to use the  }
  4. {TWMGETMINMAXINFO Windows message                            }
  5. {Original procedure for sizing for Win95/NtShell TaskBar from}
  6. {Peter M. Jagielski 73737,1761@compuserve.com.               }
  7.  
  8. {This is freeware and freely distributable, just include the }
  9. {above five lines just before the procedure in your progam.  }
  10.  
  11. {After adding this to your program, run it, maximize your     }
  12. {window, and move the task bar around the screen.  Your       }
  13. {program will automatically change its position and size.     }
  14.  
  15. {Just after your normal procedure definitions in your class(tform) type      }
  16. {and before your private variable declarataions, Add the following two lines }
  17. {Without the comment brackets of course                                      }
  18. {  private                                                                   }
  19. {    procedure mymax(var msg: TWMGETMINMAXINFO);  message wm_getminmaxinfo;  }
  20.  
  21. procedure Tform1.mymax(var msg : TWMGETMINMAXINFO);
  22. Const
  23.    MyMinimumWidth = 600;
  24.    MyMinimumHeight = 440;
  25. var
  26.   Width1,Height1,Top1,Left1:Integer;
  27.   TaskBarHandle: HWnd;    { Handle to the Win95 Taskbar }
  28.   TaskBarCoord:  TRect;   { Coordinates of the Win95 Taskbar }
  29.   CxScreen,               { Width of screen in pixels }
  30.   CyScreen,               { Height of screen in pixels }
  31.   CxFullScreen,           { Width of client area in pixels }
  32.   CyFullScreen,           { Heigth of client area in pixels }
  33.   CyCaption:     Integer; { Height of a window's title bar in pixels }
  34. begin
  35.    {Remove the next two lines if you do not require a minimum width or height}
  36.    msg.minmaxinfo^.ptMinTrackSize.x := MyMinimumWidth;
  37.    msg.minmaxinfo^.ptMinTrackSize.y := MyMinimumHeight;
  38.  
  39.    if FindWindow('Shell_TrayWnd',Nil)=0 then
  40.       begin
  41.          {Neither Windows 95 nor the NT Shell Update are running}
  42.          msg.minmaxinfo^.ptMaxTrackSize.x := GetSystemMetrics(SM_CXSCREEN);
  43.          msg.minmaxinfo^.ptMaxTrackSize.y := GetSystemMetrics(SM_CYSCREEN);
  44.       end
  45.    else
  46.       begin
  47.          { Get coordinates of Win95 Taskbar }
  48.          GetWindowRect(TaskBarHandle,TaskBarCoord);
  49.          { Get various screen dimensions and set form's width/height }
  50.          CxScreen      := GetSystemMetrics(SM_CXSCREEN);
  51.          CyScreen      := GetSystemMetrics(SM_CYSCREEN);
  52.          CxFullScreen  := GetSystemMetrics(SM_CXFULLSCREEN);
  53.          CyFullScreen  := GetSystemMetrics(SM_CYFULLSCREEN);
  54.          CyCaption     := GetSystemMetrics(SM_CYCAPTION);
  55.          Width1  := CxScreen - (CxScreen - CxFullScreen) + 1;
  56.          Height1 := CyScreen - (CyScreen - CyFullScreen) + CyCaption + 1;
  57.          Top1    := 0;
  58.          Left1   := 0;
  59.          if (TaskBarCoord.Top = -2) and (TaskBarCoord.Left = -2) then
  60.             { Taskbar on either top or left }
  61.             if TaskBarCoord.Right > TaskBarCoord.Bottom then
  62.                { Taskbar on top }
  63.                Top1  := TaskBarCoord.Bottom
  64.             else
  65.                { Taskbar on left }
  66.                Left1 := TaskBarCoord.Right;
  67.          {Set the minimum positions and sizes}
  68.          msg.MinMaxInfo^.ptMaxPosition.x  := left1;
  69.          msg.MinMaxInfo^.ptMaxPosition.y  := top1;
  70.          msg.minmaxinfo^.ptMaxTrackSize.x := Width1;
  71.          msg.minmaxinfo^.ptMaxTrackSize.y := Height1;
  72.       end;
  73. end;
  74.